package org.dromara.bclt.controller;

import java.util.List;

import lombok.RequiredArgsConstructor;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.dromara.bclt.service.DroolsPusheDataService;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import org.dromara.common.idempotent.annotation.RepeatSubmit;
import org.dromara.common.log.annotation.Log;
import org.dromara.common.web.core.BaseController;
import org.dromara.common.mybatis.core.page.PageQuery;
import org.dromara.common.core.domain.R;
import org.dromara.common.core.validate.AddGroup;
import org.dromara.common.core.validate.EditGroup;
import org.dromara.common.log.enums.BusinessType;
import org.dromara.common.excel.utils.ExcelUtil;
import org.dromara.bclt.domain.vo.InferenceLogVo;
import org.dromara.bclt.domain.bo.InferenceLogBo;
import org.dromara.bclt.service.IInferenceLogService;
import org.dromara.common.mybatis.core.page.TableDataInfo;

/**
 * 推理日志
 * 前端访问路由地址为:/bclt/inferenceLog
 *
 * @author RRyuan
 * @date 2025-05-12
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/inferenceLog")
public class InferenceLogController extends BaseController {

    private final IInferenceLogService inferenceLogService;
    private final DroolsPusheDataService droolsPusheDataService;


    /**
     * 查询推理日志列表
     */
    @SaCheckPermission("bclt:inferenceLog:list")
    @GetMapping("/list")
    public TableDataInfo<InferenceLogVo> list(InferenceLogBo bo, PageQuery pageQuery) {
//        if (bo.getClient() == null) {
//            droolsPusheDataService.inference();
//        }
        return inferenceLogService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出推理日志列表
     */
    @SaCheckPermission("bclt:inferenceLog:export")
    @Log(title = "推理日志", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(InferenceLogBo bo, HttpServletResponse response) {
        List<InferenceLogVo> list = inferenceLogService.queryList(bo);
        ExcelUtil.exportExcel(list, "推理日志", InferenceLogVo.class, response);
    }

    /**
     * 获取推理日志详细信息
     *
     * @param id 主键
     */
    @SaCheckPermission("bclt:inferenceLog:query")
    @GetMapping("/{id}")
    public R<InferenceLogVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long id) {
        return R.ok(inferenceLogService.queryById(id));
    }

    /**
     * 新增推理日志
     */
    @SaCheckPermission("bclt:inferenceLog:add")
    @Log(title = "推理日志", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody InferenceLogBo bo) {
        return toAjax(inferenceLogService.insertByBo(bo));
    }

    /**
     * 修改推理日志
     */
    @SaCheckPermission("bclt:inferenceLog:edit")
    @Log(title = "推理日志", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody InferenceLogBo bo) {
        return toAjax(inferenceLogService.updateByBo(bo));
    }

    /**
     * 删除推理日志
     *
     * @param ids 主键串
     */
    @SaCheckPermission("bclt:inferenceLog:remove")
    @Log(title = "推理日志", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] ids) {
        return toAjax(inferenceLogService.deleteWithValidByIds(List.of(ids), true));
    }
    /**
     *
     * 推理引擎接口
     */

    /**
     * 获取推理日志详细信息
     *
     * @param id 主键
     */
//    @SaCheckPermission("bclt:inferenceLog:query")
//    @GetMapping("/{id}")
//    public R<InferenceLogVo> reference(InferenceLogBo bo) {
//        return R.ok(inferenceLogService.queryByDeviceId(bo.getDeviceId()));
//    }



}
